package com.zcx.mall.oauth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zcx.mall.oauth.constant.OauthBizConstant;
import com.zcx.mall.oauth.dao.UserInfoDao;
import com.zcx.mall.oauth.entity.UserInfoEntity;
import com.zcx.mall.oauth.service.SmsService;
import com.zcx.mall.oauth.service.UserInfoService;
import com.zcx.mall.oauth.vo.RegisterUserRequest;
import com.zcx.mall.oauth.vo.SmsResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


@Service("userInfoService")
public class UserInfoServiceImpl extends ServiceImpl<UserInfoDao, UserInfoEntity> implements UserInfoService {

    @Autowired
    private SmsService smsService;

    @Override
    public UserInfoEntity selectByUsername(String username) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_name", username);
        return this.getOne(queryWrapper);
    }

    @Override
    public UserInfoEntity selectByMobile(String mobile) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mobile", mobile);
        return this.getOne(queryWrapper);
    }


    @Override
    public SmsResult register(RegisterUserRequest registerUserRequest) {
        //确认注册的真实性
        smsService.confirmSms(registerUserRequest.getSmsNo(), registerUserRequest.getMobile(), OauthBizConstant.SmsType.REGISTER);

        //查看用户


        //新增用户


        //完成免登录


        return null;
    }
}